package com.zmhz.intercept;

import java.util.Date;

import com.eova.aop.AopContext;
import com.eova.aop.MetaObjectIntercept;
import com.eova.common.utils.xx;
import com.jfinal.ext.kit.DateKit;
import com.jfinal.plugin.activerecord.Db;

public class NewsInterceptor extends MetaObjectIntercept {

	
	/**
	 * 添加新闻时，增加添加时间
	 */
	@Override
	public String addBefore(AopContext ac) throws Exception {
		String now = DateKit.toStr(new Date(), DateKit.datePattern);
		ac.record.set("addtime", now);
		
        return null;
    }
	/**
	 * 删除会员信息时修改用户状态为注册用户
	 */
	@Override
	public void queryAfter(AopContext ac) throws Exception {
		if(!xx.isEmpty(ac.record)) {
			Integer id = ac.record.getInt("id");
			String sql = "update zm_news set viewsnum=viewsnum+1 where id=?";
			Db.update(sql, id);
		}
		
    }
}
